
package com.benimetum.managers;

import com.benimetum.beans.HomePageBean;
import com.benimetum.items.Person;
import javax.faces.context.FacesContext;

/**
 *
 * @author Ethem Cem Ozkan
 * @email ethemcem.ozkan@gmail.com
 * No 07110604
 */
public class LoginManager
{
    /**
     * login olan kullanıcı öğretmenmi
     * @return 
     */
    public static boolean isTeacher(){
        FacesContext context = FacesContext.getCurrentInstance();
	  HomePageBean obj = context.getApplication().evaluateExpressionGet(context, "#{HomePageBean}", HomePageBean.class);
            Person user = obj.getUser();
	  return user.isTeacher();
    }

    public static Person getUser() {
	  FacesContext context = FacesContext.getCurrentInstance();
	  HomePageBean obj = context.getApplication().evaluateExpressionGet(context, "#{HomePageBean}", HomePageBean.class);
          return obj.getUser();
    }

    public static void setUser(Person user) {
	  FacesContext context = FacesContext.getCurrentInstance();
	  HomePageBean obj = context.getApplication().evaluateExpressionGet(context, "#{HomePageBean}", HomePageBean.class);
          obj.setUser(user);
    }
    
    public static String getWelcomeText(){
          FacesContext context = FacesContext.getCurrentInstance();
	  HomePageBean obj = context.getApplication().evaluateExpressionGet(context, "#{HomePageBean}", HomePageBean.class);
        Person user = obj.getUser();
	  return "Merhaba "+user.getFirstName()+"  ";
    }
    
    public static String getPassword(String id){
	  if(id.startsWith("st"))
		return StudentManager.getPassword(id);
	  else if(id.startsWith("t"))
		return TeacherManager.getPassword(id);
	  return null;
    }
}
